<?php
require_once "./db_config.php";
$arr=[];
$name=$_POST['name'];
if($name==''){
    $sql="SELECT DISTINCT 
    `科室`
    FROM
    personalfiles WHERE trim(科室)!=''";
    $result=mysqli_query($conn,$sql);
    if (mysqli_num_rows($result) > 0) {
    // 输出数据
        while($row = mysqli_fetch_array($result)) {
            array_push($arr,$row);
        }
    } else {
        echo "0 结果";
    }
}
else{
    $sql="SELECT
    `姓名`,`工号`,`科室`,`人员层级`,`管理职务`
    FROM
    personalfiles 
    WHERE 
    科室='$name'";
    $result=mysqli_query($conn,$sql);
    if (mysqli_num_rows($result) > 0) {
    // 输出数据
        while($row = mysqli_fetch_array($result)) {
            array_push($arr,$row);
        }
    } else {
        echo "0 结果";
    }
}

echo json_encode($arr,JSON_UNESCAPED_UNICODE);
mysqli_close($conn);
?>